<template>
  <div class="container">
    <el-dialog title="题目预览" :visible.sync="show" width="900px" @close="close()">
      <el-row>
        <el-col :span="6">【题型】:{{questionType}}</el-col>
        <el-col :span="6">【编号】:{{myData.id}}</el-col>
        <el-col :span="6">【难度】:{{difficulty}}</el-col>
        <el-col :span="6">【标签】:{{myData.tags}}</el-col>
        <el-col :span="6">【学科】:{{myData.subjectName}}</el-col>
        <el-col :span="6">【目录】:{{myData.catalogID}}</el-col>
        <el-col :span="6">【方向】:{{myData.direction}}</el-col>
      </el-row>
      <hr />【题目】：
      <div v-html="myData.question"></div>
      <div v-if="myData.questionType!=='3'">
        <div style="padding-bottom:5px">{{myData.questionType}} 选项：（以下选中的选项为正确答案）</div>
        <div v-for="item in myData.options" :key="item.code" style="padding:8px 0">
          <el-radio v-if="myData.questionType==='1'" :value="item.isRight" :label="1">{{item.title}}</el-radio>
          <el-checkbox
            v-if="myData.questionType==='2'"
            :value="item.isRight?true:false"
          >{{item.title}}</el-checkbox>
        </div>
      </div>
      <hr />【参考答案】：
      <el-button type="danger" size="small" @click="preivewVideo()">视频答案预览</el-button>
      <div class="video" v-show="play">
        <video ref="video" :src="myData.videoURL" controls></video>
      </div>
      <hr />【答案解析】：
      <div style="display:inline-block" v-html="myData.answer"></div>
      <hr />
      【题目备注】：{{myData.remarks}}
    </el-dialog>
  </div>
</template>

<script>
import { detail } from "@/api/hmmm/questions";
export default {
  props: {
    date: {
      type: Object,
      require: true,
    },
  },
  data() {
    return {
      play: false,
      show: false,
      myData: {},
    };
  },
  methods: {
    async open() {
      this.show = true;
      const res = await detail({ id: this.date.id });
      console.log(res);
      this.myData = res.data;
    },
    preivewVideo() {
      this.play = true;
      this.$refs.video.play();
    },
    close() {
      this.play = false;
      this.$refs.video.pause();
    },
  },
  computed: {
    questionType() {
      if (this.myData.questionType === "1") {
        return "单选";
      }
      if (this.myData.questionType === "2") {
        return "多选";
      }
      if (this.myData.questionType === "3") {
        return "简答";
      }
    },
    difficulty() {
      if (this.myData.difficulty === "1") {
        return "简单";
      }
      if (this.myData.difficulty === "2") {
        return "一般";
      }
      return "困难";
    },
  },
};
</script>

<style scoped lang='less'>
.container {
  .video {
    width: 400px;
    height: 300px;
    video {
      width: 100%;
      height: 100%;
    }
  }
}
</style>
